﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Dotnet.Code
{
    public interface ICache
    {
        #region 添加缓存
        bool AddCache<T>(T value, string cacheKey) where T : class;
        bool AddCache<T>(T value, string cacheKey, int expireTime) where T : class;
        bool AddCache<T>(T value, string cacheKey, TimeSpan span) where T : class;
        event CacheRemoveEventHandler CacheRemove;
        #endregion



        #region
        T GetCache<T>(string cacheKey) where T : class;
        T GetCache<T>(string cacheKey, string regionName) where T : class;
        /// <summary>
        /// 写入一个不过期缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="cacheKey"></param>
        void WriteCache<T>(T value, string cacheKey) where T : class;
        /// <summary>
        /// 写入一个带有区域但不过期的缓存。
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="cacheKey"></param>
        /// <param name="regionName"></param>
        void WriteCache<T>(T value, string cacheKey, string regionName) where T : class;
        /// <summary>
        /// 写入一个有过期时间的缓存
        /// </summary>
        /// <typeparam name="T">数据类型</typeparam>
        /// <param name="value">数据值</param>
        /// <param name="cacheKey">缓存名称</param>
        /// <param name="expireTime">过期时间，以秒为单位</param>
        void WriteCache<T>(T value, string cacheKey, int expireTime) where T : class;
        /// <summary>
        /// 写入一个有区域且有过期时间的缓存
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="value"></param>
        /// <param name="cacheKey"></param>
        /// <param name="regionName"></param>
        void WriteCache<T>(T value, string cacheKey, string regionName, int expireTime) where T : class;
        void RemoveCache(string cacheKey);
        void RemoveCache();
        #endregion
    }
}
